package com.easy;

/**
 * Created by Lxk on 2019/3/16.
 */
@SuppressWarnings("Duplicates")
public class Solution82 {
    public ListNode deleteDuplicates(ListNode head) {
        if(head == null){
            return head;
        }
        ListNode cur = new ListNode(Integer.MIN_VALUE);
        cur.next = head;
        head = cur;
        ListNode pre = head;
        cur = head.next;
        ListNode end = cur.next;
        while(end!=null){
            boolean catcher = false;
            while(end!=null && ((Integer)end.val).equals(cur.val)){
                catcher = true;
                end = end.next;
            }
            if(catcher){
                pre.next = end;
                catcher = false;
            }else{
                pre = pre.next;
            }
            cur = pre.next;
            if(cur != null){
                end = cur.next;
            }
        }
        return head.next;
    }
}
